package com.bilibili.server.controller;

import com.bilibili.model.vo.CommentVo;
import com.bilibili.model.vo.PageResult;
import com.bilibili.server.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author HuangRongFu
 * 2021/11/22 星期一5:50 下午
 */

@RestController
@RequestMapping("/comments")
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 查看评论列表
     *
     * @param: page
     * @param: pageSize
     * @param: movementId
     * @Return: ResponseEntity
     */
    @GetMapping
    public ResponseEntity commentsList(@RequestParam(defaultValue = "1") Long page,
                                       @RequestParam(value = "pagesize", defaultValue = "10") Long pageSize,
                                       String movementId) {
        PageResult<CommentVo> pageResult = commentService.findComments(page, pageSize, movementId);

        return ResponseEntity.ok(pageResult);
    }

    /**
     * 发布评论
     *
     * @param: paramMap
     * @Return: ResponseEntity
     */
    @PostMapping
    public ResponseEntity commentsList(@RequestBody Map<String, String> paramMap) {

        commentService.addComment(paramMap);

        return ResponseEntity.ok(null);
    }


}
